import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2024-03-30
 * Time: 23:24
 */
public class Test2 {


    public static void main(String[] args) {
        // 现有两个 ArrayList 集合：
        // 第一个集合：存储 6 名男演员的名字和年龄；第二个集合：存储 6 名女演员的名字和年龄
        ArrayList<String> manList = new ArrayList<>();
        ArrayList<String> womanList = new ArrayList<>();
        Collections.addAll(manList,"蔡坤坤,24","叶厚贤,23,","刘不甜,22","吴倩,24","蔡加,30","肖亮亮,27");
        Collections.addAll(womanList,"赵晓英,35","杨颖,36","高媛媛,43","刘诗,35","杨小敏,33");

        // 需求1：男演员只要名字为 3 个字的前两人
        Stream<String> stream1 = manList.stream().filter(s -> s.split(",")[0].length() == 3)
                .limit(2);

        // 需求2：女演员只要姓杨的，并且不要第一个
        Stream<String> stream2 = womanList.stream().filter(s -> s.split(",")[0].startsWith("杨"))
                .skip(1);

        // 需求3：把过滤后的男演员姓名和女演员合并到一起封装成 Actor 对象（Actor 对象属性有 name、age）
//        Stream<Actor> stream3 = Stream.concat(stream1, stream2)
//                .map(s -> new Actor(s.split(",")[0], Integer.parseInt(s.split(",")[1])));
        Stream<Actor> stream3 = Stream.concat(stream1, stream2)
                .map(s -> {
                    Actor actor = new Actor();
                    actor.setName(s.split(",")[0]);
                    actor.setAge(Integer.parseInt(s.split(",")[1]));
                    return actor;
                });

        // 需求5：将所有的演员对象都报存到 List 集合中
        stream3.collect(Collectors.toList()).forEach(s -> System.out.println(s));

    }

}
